home *** CD-ROM | disk | FTP | other *** search
/ EuroCD 3 / EuroCD 3.iso / Games / Doom / ADoom-0.8 / ADoom_src / st_lib.c < prev    next >
C/C++ Source or Header  |  1998-06-24  |  5KB  |  294 lines

  1. // Emacs style mode select   -*- C++ -*- 
  2. //-----------------------------------------------------------------------------
  3. //
  4. // $Id:$
  5. //
  6. // Copyright (C) 1993-1996 by id Software, Inc.
  7. //
  8. // This source is available for distribution and/or modification
  9. // only under the terms of the DOOM Source Code License as
  10. // published by id Software. All rights reserved.
  11. //
  12. // The source is distributed in the hope that it will be useful,
  13. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License
  15. // for more details.
  16. //
  17. // $Log:$
  18. //
  19. // DESCRIPTION:
  20. //    The status bar widget code.
  21. //
  22. //-----------------------------------------------------------------------------
  23.  
  24.  
  25. static const char
  26. rcsid[] = "$Id: st_lib.c,v 1.4 1997/02/03 16:47:56 b1 Exp $";
  27.  
  28. #include <ctype.h>
  29.  
  30. #include "doomdef.h"
  31.  
  32. #include "z_zone.h"
  33. #include "v_video.h"
  34.  
  35. #include "m_swap.h"
  36.  
  37. #include "i_system.h"
  38.  
  39. #include "w_wad.h"
  40.  
  41. #include "st_stuff.h"
  42. #include "st_lib.h"
  43. #include "r_local.h"
  44.  
  45.  
  46. // in AM_map.c
  47. extern boolean        automapactive; 
  48.  
  49.  
  50.  
  51.  
  52. //
  53. // Hack display negative frags.
  54. //  Loads and store the stminus lump.
  55. //
  56. patch_t*        sttminus;
  57.  
  58. void STlib_init(void)
  59. {
  60.     sttminus = (patch_t *) W_CacheLumpName("STTMINUS", PU_STATIC);
  61. }
  62.  
  63.  
  64. // ?
  65. void
  66. STlib_initNum
  67. ( st_number_t*        n,
  68.   int            x,
  69.   int            y,
  70.   patch_t**        pl,
  71.   int*            num,
  72.   boolean*        on,
  73.   int            width )
  74. {
  75.     n->x    = x;
  76.     n->y    = y;
  77.     n->oldnum    = 0;
  78.     n->width    = width;
  79.     n->num    = num;
  80.     n->on    = on;
  81.     n->p    = pl;
  82. }
  83.  
  84.  
  85. // 
  86. // A fairly efficient way to draw a number
  87. //  based on differences from the old number.
  88. // Note: worth the trouble?
  89. //
  90. void
  91. STlib_drawNum
  92. ( st_number_t*    n,
  93.   boolean    refresh )
  94. {
  95.  
  96.     int        numdigits = n->width;
  97.     int        num = *n->num;
  98.     
  99.     int        w = SHORT(n->p[0]->width);
  100.     int        h = SHORT(n->p[0]->height);
  101.     int        x = n->x;
  102.     
  103.     int        neg;
  104.  
  105.     n->oldnum = *n->num;
  106.  
  107.     neg = num < 0;
  108.  
  109.     if (neg)
  110.     {
  111.     if (numdigits == 2 && num < -9)
  112.         num = -9;
  113.     else if (numdigits == 3 && num < -99)
  114.         num = -99;
  115.     
  116.     num = -num;
  117.     }
  118.  
  119.     // clear the area
  120.     x = n->x - numdigits*w;
  121.  
  122.     if (n->y - ST_Y < 0)
  123.     I_Error("drawNum: n->y - ST_Y < 0");
  124.  
  125.     V_CopyRect(x, n->y - ST_Y, BG, w*numdigits, h, x, n->y, FG);
  126.  
  127.     // if non-number, do not draw it
  128.     if (num == 1994)
  129.     return;
  130.  
  131.     x = n->x;
  132.  
  133.     // in the special case of 0, you draw 0
  134.     if (!num)
  135.     V_DrawPatch(x - w, n->y, FG, n->p[ 0 ]);
  136.  
  137.     // draw the new number
  138.     while (num && numdigits--)
  139.     {
  140.     x -= w;
  141.     V_DrawPatch(x, n->y, FG, n->p[ num % 10 ]);
  142.     num /= 10;
  143.     }
  144.  
  145.     // draw a minus sign if necessary
  146.     if (neg)
  147.     V_DrawPatch(x - 8, n->y, FG, sttminus);
  148. }
  149.  
  150.  
  151. //
  152. void
  153. STlib_updateNum
  154. ( st_number_t*        n,
  155.   boolean        refresh )
  156. {
  157.     if (*n->on) STlib_drawNum(n, refresh);
  158. }
  159.  
  160.  
  161. //
  162. void
  163. STlib_initPercent
  164. ( st_percent_t*        p,
  165.   int            x,
  166.   int            y,
  167.   patch_t**        pl,
  168.   int*            num,
  169.   boolean*        on,
  170.   patch_t*        percent )
  171. {
  172.     STlib_initNum(&p->n, x, y, pl, num, on, 3);
  173.     p->p = percent;
  174. }
  175.  
  176.  
  177.  
  178.  
  179. void
  180. STlib_updatePercent
  181. ( st_percent_t*        per,
  182.   int            refresh )
  183. {
  184.     if (refresh && *per->n.on)
  185.     V_DrawPatch(per->n.x, per->n.y, FG, per->p);
  186.     
  187.     STlib_updateNum(&per->n, refresh);
  188. }
  189.  
  190.  
  191.  
  192. void
  193. STlib_initMultIcon
  194. ( st_multicon_t*    i,
  195.   int            x,
  196.   int            y,
  197.   patch_t**        il,
  198.   int*            inum,
  199.   boolean*        on )
  200. {
  201.     i->x    = x;
  202.     i->y    = y;
  203.     i->oldinum     = -1;
  204.     i->inum    = inum;
  205.     i->on    = on;
  206.     i->p    = il;
  207. }
  208.  
  209.  
  210.  
  211. void
  212. STlib_updateMultIcon
  213. ( st_multicon_t*    mi,
  214.   boolean        refresh )
  215. {
  216.     int            w;
  217.     int            h;
  218.     int            x;
  219.     int            y;
  220.  
  221.     if (*mi->on
  222.     && (mi->oldinum != *mi->inum || refresh)
  223.     && (*mi->inum!=-1))
  224.     {
  225.     if (mi->oldinum != -1)
  226.     {
  227.         x = mi->x - SHORT(mi->p[mi->oldinum]->leftoffset);
  228.         y = mi->y - SHORT(mi->p[mi->oldinum]->topoffset);
  229.         w = SHORT(mi->p[mi->oldinum]->width);
  230.         h = SHORT(mi->p[mi->oldinum]->height);
  231.  
  232.         if (y - ST_Y < 0)
  233.         I_Error("updateMultIcon: y - ST_Y < 0");
  234.  
  235.         V_CopyRect(x, y-ST_Y, BG, w, h, x, y, FG);
  236.     }
  237.     V_DrawPatch(mi->x, mi->y, FG, mi->p[*mi->inum]);
  238.     mi->oldinum = *mi->inum;
  239.     }
  240. }
  241.  
  242.  
  243.  
  244. void
  245. STlib_initBinIcon
  246. ( st_binicon_t*        b,
  247.   int            x,
  248.   int            y,
  249.   patch_t*        i,
  250.   boolean*        val,
  251.   boolean*        on )
  252. {
  253.     b->x    = x;
  254.     b->y    = y;
  255.     b->oldval    = 0;
  256.     b->val    = val;
  257.     b->on    = on;
  258.     b->p    = i;
  259. }
  260.  
  261.  
  262.  
  263. void
  264. STlib_updateBinIcon
  265. ( st_binicon_t*        bi,
  266.   boolean        refresh )
  267. {
  268.     int            x;
  269.     int            y;
  270.     int            w;
  271.     int            h;
  272.  
  273.     if (*bi->on
  274.     && (bi->oldval != *bi->val || refresh))
  275.     {
  276.     x = bi->x - SHORT(bi->p->leftoffset);
  277.     y = bi->y - SHORT(bi->p->topoffset);
  278.     w = SHORT(bi->p->width);
  279.     h = SHORT(bi->p->height);
  280.  
  281.     if (y - ST_Y < 0)
  282.         I_Error("updateBinIcon: y - ST_Y < 0");
  283.  
  284.     if (*bi->val)
  285.         V_DrawPatch(bi->x, bi->y, FG, bi->p);
  286.     else
  287.         V_CopyRect(x, y-ST_Y, BG, w, h, x, y, FG);
  288.  
  289.     bi->oldval = *bi->val;
  290.     }
  291.  
  292. }
  293.  
  294.